package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dto.LogisticsCompanyDTO;
import com.itheima.pojo.LogisticsCompany;
import com.itheima.service.LogisticsCompanyService;
import com.itheima.vo.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/logistics/company")
@RequiredArgsConstructor
public class LogisticsCompanyController {

    private final LogisticsCompanyService companyService;

    @GetMapping("/page")
    public Page<LogisticsCompanyDTO> getCompanyPage(Page<LogisticsCompanyDTO> page, LogisticsCompanyDTO dto) {
        return companyService.getCompanyPage(page, dto);
    }

    @GetMapping("/{id}")
    public LogisticsCompanyDTO getCompanyWithPrices(@PathVariable Integer id) {
        return companyService.getCompanyWithPrices(id);
    }

    @PostMapping
    public Result saveCompany(@RequestBody LogisticsCompany company) {
        return Result.success(companyService.saveCompany(company));
    }

    @PutMapping
    public Result updateCompany(@RequestBody LogisticsCompany company) {
        return Result.success(companyService.updateCompany(company));
    }

    @DeleteMapping("/{id}")
    public Result deleteCompany(@PathVariable Integer id) {
        return Result.success(companyService.deleteCompany(id));
    }
}